#include<iostream>
using namespace std;
#include<sys/types.h>
#include<unistd.h>
#include<vector>

const int num = 10;

void SubProcessRun()
{
  while(true)
  {
    cout<<"I am sub process,pid: "<<getpid()<<",ppid: "<<getppid()<<endl;
    sleep(1);
  }
}

int main()
{
  vector<pid_t> allchild;
  for(int i = 0;i<num;i++)
  {
    pid_t id = fork();
    
    if(id==0)
    {
      //子进程
      SubProcessRun();
    }
   
    //这里由父进程一人执行
    allchild.push_back(id);
  }
  
  //父进程
  cout<<"我都所有孩子是:"<<endl;
  for(auto child:allchild)
  {
    cout<<child<<" ";
  }
  cout<<endl;

  while(true)
  {
    cout<<"我是父进程,pid: "<<getpid()<<endl;
    sleep(1);
  }

  return 0;

}
